<template>
	<view class="container padding-top-sm">
		<view class="bg-white">
			<!-- <view class="flex justify-between align-center text-13 padding">
				<view class="text-333 text-bold">
					实名认证
				</view>
				<view class="flex justify-start align-center text-666">
					<view class="" v-if='userInfo.username'>
						{{userInfo.username}} {{userInfo.userIdCard}}
					</view>
					<view v-else class="" @click="toPage('/filePage/pages/real-name/real-name')">
						还未实名认证
					</view>
					<view class="cuIcon-right margin-left-xs">

					</view>
				</view>
			</view> -->
			<view class="flex justify-between align-center text-13 padding"
				@click="toPage('/filePage/pages/address-list/address-list')">
				<view class="text-333 text-bold">
					配送地址
				</view>
				<view class="flex justify-start align-center text-666">
					<view class="">
						{{address ||'无默认收货地址'}}
					</view>
					<view class="cuIcon-right margin-left-xs">

					</view>
				</view>
			</view>
		</view>
		
		
	
		<view class="bg-white margin-top-sm">
		
			<view  
			@click="toPage('/pagesA/pages/setPassword/setPassword')"
			class="flex justify-between align-center text-13 padding">
				<view class="text-333 text-bold">
					设置支付密码
				</view>
				<view class="flex justify-start align-center text-666">
				
					<view class="cuIcon-right margin-left-xs">

					</view>
				</view>
			</view>
		</view>
		<!--  #ifdef  APP-PLUS -->
		<view class="bg-white margin-top-sm">
		
			<view  
			@click="toPage('/pagesA/pages/upLoginPwd/upLoginPwd',1)"
			class="flex justify-between align-center text-13 padding">
				<view class="text-333 text-bold">
					设置登陆密码
				</view>
				<view class="flex justify-start align-center text-666">
				
					<view class="cuIcon-right margin-left-xs">
		
					</view>
				</view>
			</view>
		</view>
		
		<button class="btn bg-color5 text-15 text-white padding round margin-sm" @click="logut">退出登录</button>
			<!--  #endif -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				address: ''
			};
		},


		onShow() {
			this.getUser()
			this.getAddress()
		},
		methods: {
			// #ifdef  APP-PLUS
			logut() {
				uni.showModal({
					title: '提示',
					content: '你确定要退出吗',
					success: function(res) {
						if (res.confirm) {
							try {
								uni.clearStorageSync();
								uni.clearStorage();
								uni.redirectTo({
									url: '/pages/login/login'
								});
							} catch (e) {
								// error
							}
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// #endif
			toPage(url,state) {
				if(state){
					if(!this.userInfo.mobile){
						uni.navigateTo({
							url: '/pages/regesiter/regesiter?type=2&state=1'
						})
					}else{
						this.$util.openNewPage(url)
					}
				}else{
					this.$util.openNewPage(url)
				}
				
			},
			async getUser() {
				const [err, rs] = await this.$get(this.$api.userDetail)
				if (rs) {
					console.log(rs)
					this.userInfo = rs.data
					uni.setStorageSync("userInfo", rs.data);
					if (rs.data.shopIdApply) {
						uni.setStorageSync('shopIdApply', rs.data.shopIdApply);
					}

					if (rs.data.shopServiceIdApply) {
						uni.setStorageSync('shopServiceIdApply', rs.data.shopServiceIdApply);
					}
					console.log(this.userInfo)
				}
			},
			async getAddress() {
				const obj = {
					userId: uni.getStorageSync('userId'),
					pageNum: 1,
					pageSize: 99,
				}
				const [err, res] = await this.$get(this.$api.addressList, obj)
				if (res) {
			         let state = res.data.list.find(val => val.isdefault == 1)
					console.log(state)
					if (state) {
						this.address = state.addressInfo
					}else{
						this.address = ''
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
 .btn{
	 position: fixed;
	 bottom: 40rpx;
	 left:0;
	 right: 0;
 }
</style>
